package com.shenma2009.thread;

import com.alibaba.fastjson2.JSON;
import com.shenma2009.config.Config;
import com.shenma2009.netty.client.WebSocketClient;
import com.shenma2009.vo.VehiclePositionVo;

import java.util.List;
import java.util.concurrent.Callable;

/**
 * @author 12692
 * @version 1.0
 * @description: SendPositionThread
 * @date 2023/5/29 15:42
 */

public class SendPositionThread implements Callable<Boolean> {

    private List<String> list;
    private WebSocketClient webSocketClient;
    private String vin;

    public SendPositionThread(List<String> list, WebSocketClient webSocketClient, String vin) {
        this.list = list;
        this.webSocketClient = webSocketClient;
        this.vin = vin;
    }

    @Override
    public Boolean call() throws Exception {

        VehiclePositionVo positionVo = new VehiclePositionVo();
        for(String position : list) {
            positionVo.setVin(vin);

            String[] split = position.split(",");

            positionVo.setLongitude(split[0]);
            positionVo.setLatitude(split[1]);

            String msg = JSON.toJSONString(positionVo);

            webSocketClient.pushMsg(Config.VEHICLE_CURRENT_LOCATION+msg);

            Thread.sleep(200);
        }

        return true;
    }
}
